//
//  JXBaseTableViewController.swift
//  01-weiboSwift
//
//  Created by TwistFate on 16/2/27.
//  Copyright © 2016年 TwistFate. All rights reserved.
//

import UIKit

class JXBaseTableViewController: UITableViewController {

    let userLogin = JXUserAcountViewModel.sharedInstance.isUserLogin
    
    override func loadView() {
        userLogin ? super.loadView() : setupVistorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.separatorStyle = UITableViewCellSeparatorStyle.None
    }
    
    func setupVistorView (){
        baseView = JXBaseView()
        
        view = baseView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "baseViewRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "baseViewLogin")
        
        
        baseView.baseViewDelegate = self
        
        if self is JXHomeController {
            baseView.startAnimation()
        } else if self is JXMessageController{
            baseView.setupVistotInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is JXDiscoverController{
            baseView.setupVistotInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is JXProfileController{
            baseView.setupVistotInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
    }
    
    lazy var baseView : JXBaseView = JXBaseView()
    
}

// MARK: - JXBaseTableViewController 扩展,实现 JXBaseViewDelegate 协议
// 扩展,和oc category类似, estension 可以实现协议, 方便代码统一管理
extension JXBaseTableViewController : JXBaseViewDelegate{

    func baseViewRegister() {
        print("baseViewRegister")
        //测试单例
        let test = JXNetworkTool.sharedInstance
        print("test:\(test.oauthLoginUrl())")
    }
    
    func baseViewLogin() {
        print("baseViewLogin")
        let oauthVC = JXOauthController()
        
        
        navigationController?.presentViewController(UINavigationController(rootViewController: oauthVC), animated:true, completion: nil)
    }
}